891B - Gluttony - CodeForces Solution


constructive algorithms greedy *2000

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>


using  namespace  std;


pair<int,int> a[100];
int b[100];

bool cmp(pair<int,int> a,pair<int,int> b)
{
    return a.first>b.first;
}

int main()
{
    int n;
    cin>>n;
    for (int i=0;i<n;i++)
    {
        cin>>a[i].first;
        a[i].second=i;
    }
    sort(a,a+n,cmp);
    for (int i=0;i<n-1;i++)
    {
        int pos=a[i+1].second;
        b[pos]=a[i].first;
    }
    b[a[0].second]=a[n-1].first;
    
    for (int i=0;i<n;i++)
    {
        cout<<b[i]<<" ";
    }

    return 0;
}

 	 				 	  	 				 	  			 		 		


Comments

Submit
0 Comments
More Questions

244A - Dividing Orange
1061C - Multiplicity
1312A - Two Regular Polygons
801A - Vicious Keyboard
510B - Fox And Two Dots
616D - Longest k-Good Segment
1604A - Era
555B - Case of Fugitive
551A - GukiZ and Contest
1399F - Yet Another Segments Subset
1371C - A Cookie for You
430B - Balls Game
1263A - Sweet Problem
1332B - Composite Coloring
254A - Cards with Numbers
215A - Bicycle Chain
1288B - Yet Another Meme Problem
1201C - Maximum Median
435A - Queue on Bus Stop
1409B - Minimum Product
723B - Text Document Analysis
1471C - Strange Birthday Party
1199A - City Day
1334A - Level Statistics
67B - Restoration of the Permutation
1734A - Select Three Sticks
1734B - Bright Nice Brilliant
357B - Flag Day
937A - Olympiad
1075A - The King's Race